const app = getApp()
var queryUrl = app.globalData.queryUrl;
var start;
var QQMapWX = require('../../../utils/qqmap-wx-jssdk.min.js');
var qqmapsdk;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    head: [],
    posits: {},
    currentData: 0,
    // deliver: '',
    textFlag: false,
    text: "",
    gps: false,
    follow: '', //关注
    longitude: '',
    latitude: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    var that = this
    var shopId = options.shopId
    var follow = options.follow
    var latitude = options.latitude
    var longitude = options.longitude
    console.log(follow)
    console.log(longitude)
    that.setData({
      follow: follow
    })
    try {
      var openId = wx.getStorageSync('openId')
    } catch (e) {}
    qqmapsdk = new QQMapWX({
      key: 'USJBZ-3LH6D-JWD4K-PYRYA-3DR32-SMBVJ' // 必填
    });
    wx.request({
      url: queryUrl + 'selectShop',
      data: {
        // id:shopId  //传参
        id: shopId,
        opendId: openId,
      },
      method: 'post',
      success: function(res) {
        console.log(res)
        that.setData({
          head: res.data.data.shop[0]
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  // 分享
  onShareAppMessage: function(res) {
    // console.log(res);
    if (res.from === "share") {}
    return {
      title: "哈哈",
      desc: "我是中国人",
      path: "pages/resume/click/purchase",
      imageUrl: "../../../images/pic3.png",
      success: function(res) {
        console.log("成功", res);

      }
    }
  },
  //获取当前滑块的index
  bindchange: function(e) {
    let that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    let that = this;
    var current = that.data.currentData
    var en = e.target.dataset.current
    if (current === en) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
    if (en == "2") {
      let that = this;
      wx.request({
        url: queryUrl + 'recruit/select',
        data: {
          shopId: "1",
        },
        method: 'post',
        success: function(res) {
          console.log(res.data)
          that.setData({
            posits: res.data.data.recruit
          })
        }
      })
    }

  },
  // 返回上一页
  navigateBack: function() {
      wx.switchTab({
        url: "../index/index"
      }); 
  },
  activeGo: function(e) {
    var shopId = e.currentTarget.dataset.shopid //传参数到另一个页面
    wx.navigateTo({
      url: '../active/active?shopId=' + shopId,
    })
  },
  // toaddress: function (e) {
  //   console.log(e)
  //   var id = e.markerId
  //   console.log(id)
  // },
  addheight: function() {
    this.setData({
      textFlag: !this.data.textFlag
    })
  },
  // 打电话
  goPhone: function() {
    wx.makePhoneCall({
      phoneNumber: '1340000'
    })
  },
  // 关注
  attenTion: function(e) {
    var that = this
    var follow = that.data.follow
    console.log(follow)
    if (follow == 1) {
      follow = null //取关
      wx.request({
        url: queryUrl + 'deleteFav',
        data: {
          opendId: that.data.openId,
          shopId: '1'
        },
        method: 'post',
        success: function(res) {
          console.log(res)
        }
      })
      //提示用户
      wx.showToast({
        title: '取消关注',
        icon: 'success'
      })
    } else {
      follow = 1
      wx.request({
        url: queryUrl + 'registerFav',
        data: {
          opendId: that.data.openId,
          shopId: '1'
        },
        method: 'post',
        success: function(res) {
          console.log(res)
        }
      })
      //提示用户
      wx.showToast({
        title: '已关注',
        icon: 'success'
      })
    }
    that.setData({
      follow: follow
    })
  },
  // 投递简历
  deLivery: function(e) {
    var that = this
    var deliver = e.currentTarget.dataset.deliver
    if (deliver != 1){
      deliver = 1
      //提示用户
      wx.showToast({
        title: '投递成功',
        icon: 'success'
      })
    }
    console.log(deliver)
  },
  goVideos:function(){
    wx.navigateTo({
      url: '../../theVideo/theVideo',
    })
  }
})